package wwek6;

import java.util.Arrays;
import java.util.Scanner;

class PersonSortable implements Comparable<PersonSortable>{
	private String name;
	private int age;
	
	@Override
	public int compareTo(PersonSortable o) {
		if(name.compareTo(o.name)==0){
			if(age>o.age)
				return age-o.age;
			if(age==o.age)
				return 0;
			else
				return -1;
		}
		else
			return name.compareTo(o.name);
	}

	public PersonSortable(String name, int age) {
		super();
		this.name = name;
		this.age = age;
	}

	@Override
	public String toString() {
		return name+"-"+age;
	}
	
}



public class PTA720401 {


	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int t=in.nextInt();
		PersonSortable[] stus = new PersonSortable[t];
		for(int i=0; i<t;i++){
			PersonSortable a = new PersonSortable(in.next(),in.nextInt());
			stus[i]=a;
		}
		Arrays.sort(stus);
		for(int i=0;i<t;i++)
			System.out.println(stus[i]);
		System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));

	}

}